//
//  WZPThemeCell.m
//  WZPItem
//
//  Created by 王王喆平 on 16/7/14.
//  Copyright © 2016年 UI. All rights reserved.
//

#import "WZPThemeCell.h"
#import "WZPTopView.h"
#import "WZPThemePictureView.h"
#import "WZPThemeModel.h"
#import "WZPThemeItem.h"
#import "WZPThemeVideo.h"
#import "WZPThemeVicoe.h"
#import "WZPHotCommentView.h"
#import "WZPThemeBottom.h"

@interface WZPThemeCell()

@property (nonatomic,weak)WZPTopView * topView;
@property (nonatomic,weak)WZPThemePictureView * pictureView;
@property (nonatomic,weak)WZPThemeVideo * videoView;
@property (nonatomic,weak)WZPThemeVicoe * vicoeView;
@property (nonatomic,weak)WZPHotCommentView * commentView;
@property (nonatomic,weak)WZPThemeBottom *bottomView;

@end
@implementation WZPThemeCell

-(void)setFrame:(CGRect)frame{
    
    frame.size.height -= 30;
    frame.origin.y += 10;
    
    [super setFrame:frame];

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        // 对cell 添加背景图片
        UIImage * image = [UIImage imageNamed:@"mainCellBackground"];
        image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
        self.backgroundView = [[UIImageView alloc]initWithImage:image];
        // 添加顶部
        WZPTopView * topView = [WZPTopView viewForXid];
        [self.contentView addSubview:topView];
        _topView = topView;
        // 添加图片
        WZPThemePictureView * pictureView = [WZPThemePictureView viewForXid];
        [self.contentView addSubview:pictureView];
        _pictureView = pictureView;
        
        WZPThemeVideo * videoView = [WZPThemeVideo viewForXid];
        [self.contentView addSubview:videoView];
         _videoView = videoView ;
        
        WZPThemeVicoe * vicoeView = [WZPThemeVicoe viewForXid];
        [self.contentView addSubview:vicoeView];
        _vicoeView = vicoeView;
        
        WZPHotCommentView * commentView = [WZPHotCommentView viewForXid];
        [self.contentView addSubview:commentView];
        _commentView = commentView;
        
        WZPThemeBottom * bottomView = [WZPThemeBottom viewForXid];
        [self.contentView addSubview:bottomView];
        _bottomView = bottomView;

    }
    return self;
}
-(void)setModel:(WZPThemeModel *)model{
    
    _model = model;
    _topView.item = model.item;
    _topView.frame = model.topViewFrame;
    
    _pictureView.item = model.item;
    _pictureView.frame = model.midPictureViewFrame;
    // 判断中间图片类型
    if (model.item.type == WZPThemeTypePicture) {
        _pictureView.hidden = NO;
        _vicoeView.hidden = YES;
        _pictureView.item = model.item;
        _pictureView.frame = model.midPictureViewFrame;
        _videoView.hidden = YES;
        
    }else if (model.item.type == WZPThemeTypeVideo){
        _pictureView.hidden = YES;
        _vicoeView.hidden = YES;
        _videoView.hidden = NO;
        _videoView.item = model.item;
        _videoView.frame = model.midPictureViewFrame;
    
    }else if (model.item.type == WZPThemeTypeVoice){
        _pictureView.hidden = YES;
        _videoView.hidden = YES;
        _vicoeView.hidden = NO;
        _vicoeView.item = model.item;
        _vicoeView.frame = model.midPictureViewFrame;

    
    }else{
        _pictureView.hidden = YES;
        _videoView.hidden = YES;
        _vicoeView.hidden = YES;

    }
    // 判断有没有最热评论
    if (model.item.commentView) {
        _commentView.hidden = NO;
        _commentView.frame = _model.commentViewFrame;
        _commentView.item = _model.item;
    }else{
        _commentView.hidden = YES;
    }

    _bottomView.frame = _model.bottomViewFrame;
    _bottomView.item  = _model.item;

}
@end
